package com.cvte.boe.media.model;

import android.os.Bundle;

import com.cvte.boe.media.utils.DiskUtil;
import com.cvte.boe.media.utils.EncodeUtil;
import com.cvte.boe.media.utils.MediaDataUtil;
import com.cvte.boe.media.utils.constant.Constant;

import java.io.File;

public class LocalMediaInfo {

    public static final String ALBUM = "album";
    public static final String ARTIST = "artist";
    public static final String DATA = "data";
    public static final String DEVICETYPE = "devicetype";
    public static final String DURATION = "duration";
    public static final String FILES = "files";
    public static final String FILE_NAME = "name";
    public static final String FILE_SIZE = "size";
    public static final String FILE_SIZE_STR = "size_str";
    public static final String FILE_TYPE = "type";
    public static final String FOLDERS = "folders";
    public static final String MEDIA_TYPE_EXTRA = "MEDIA_TYPE_EXTRA";
    public static final String MIMETYPE = "mimetype";
    public static final String MODIFY_DATE = "last_modify_date";
    public static final String MODIFY_DATE_STR = "last_modify_date_str";
    public static final String OBJECT_ID = "object_id";
    public static final String ORDER_FIELD = "order_field";
    public static final String PARENT_PATH = "path";
    public static final String PHYSIC_ID = "physic_dev_id";
    public static final String PIN_YIN = "pinyin";
    public static final String RESOULUTION = "resoulution";
    public static final String RES_URI = "res_uri";
    public static final String THUMBNAIL = "thumbNail";
    public static final String TITLE = "title";
    public static final String FILE_ALL_NAME = "file_all_name";
    private String mAlbum;
    private String mArtist;
    private String mData;
    private int mDeleteModeState;
    private int mDeviceType;
    private String mDuration;
    private String mFileName;
    private long mFileSize;
    private String mFileSizeStr;
    private int mFileType;
    private int mFiles;
    private int mFolders;
    private String mMimeType;
    private int mModifyDate;
    private String mModifyDateStr;
    private String mObjectId;
    private int mOrderField;
    private String mParentPath;
    private String mPhysicId;
    private String mPinyin;
    private String mResUri;
    private String mResoulution;
    private String mThumbNail;
    private String mTitle;
    private String mFileAllName;

    public LocalMediaInfo() {
    }


    public LocalMediaInfo(File file) {
        setParentPath(file.getParent());
        setFileName(file.getName());
        setFileAllName(file.getAbsolutePath());
        setDeviceType(Constant.DeviceType.DEVICE_TYPE_USB);

        int type = MediaDataUtil.getMediaType(file);
        switch (type){
            case Constant.MediaType.VIDEO:
                setMimeType("video/*");
                setFileType(Constant.MediaType.VIDEO);
                break;
            case Constant.MediaType.AUDIO:
                setMimeType("audio/*");
                setFileType(Constant.MediaType.AUDIO);
                break;
            case Constant.MediaType.IMAGE:
                setMimeType("image/*");
                setFileType(Constant.MediaType.IMAGE);
                break;
            case Constant.MediaType.FOLDER:
                setMimeType("none");
                setFileType(Constant.MediaType.FOLDER);
                setFiles(file.listFiles().length);
                break;
            default:
                setMimeType("none");
                setFileType(Constant.MediaType.UNKNOWN_TYPE);
                break;
        }
        setModifyDate((int) (file.lastModified() / 0x3e8));
        setFileSize(file.length());
        setFileSizeStr(DiskUtil.getFileSizeStringL(file.length()));
        setPinyin(EncodeUtil.getFitEncodeString(file.getName()));
    }

    public Bundle compress() {
        Bundle bundle = new Bundle();
        bundle.putString(FILE_NAME, getFileName());
        bundle.putString(PARENT_PATH, getParentPath());
        bundle.putInt(FOLDERS, getFolders());
        bundle.putInt(FILES, getFiles());
        bundle.putInt(FILE_TYPE, getFileType());
        bundle.putLong(FILE_SIZE, getFileSize());
        bundle.putString(FILE_SIZE_STR,getFileSizeStr());
        bundle.putInt(ORDER_FIELD, getOrderField());
        bundle.putInt(MODIFY_DATE, getModifyDate());
        bundle.putString(MODIFY_DATE_STR, getModifyDateStr());
        bundle.putString(PIN_YIN, getPinyin());
        bundle.putString(DATA, getData());
        bundle.putString(THUMBNAIL, getThumbNail());
        bundle.putInt(DEVICETYPE, getDeviceType());
        bundle.putString(ALBUM, getAlbum());
        bundle.putString(ARTIST, getArtist());
        bundle.putString(TITLE, getTitle());
        bundle.putString(PHYSIC_ID, getPhysicId());
        bundle.putString(MIMETYPE, getMimeType());
        bundle.putString(RES_URI, getResUri());
        bundle.putString(OBJECT_ID, getObjectId());
        bundle.putString(RESOULUTION, getResoulution());
        bundle.putString(DURATION, getDuration());
        bundle.putString(FILE_ALL_NAME,getFileAllName());
        return bundle;
    }

    public void decompress(Bundle bundle) {
        setFileName(bundle.getString(FILE_NAME));
        setParentPath(bundle.getString(PARENT_PATH));
        setFolders(bundle.getInt(FOLDERS, 0x0));
        setFiles(bundle.getInt(FILES, 0x0));
        setFileType(bundle.getInt(FILE_TYPE, -0x1));
        setFileSize(bundle.getLong(FILE_SIZE, 0x0));
        setFileSizeStr(bundle.getString(FILE_SIZE_STR));
        setOrderField(bundle.getInt(ORDER_FIELD, 0x0));
        setModifyDate(bundle.getInt(MODIFY_DATE, 0x0));
        setModifyDateStr(bundle.getString(MODIFY_DATE_STR));
        setPinyin(bundle.getString(PIN_YIN));
        setData(bundle.getString(DATA));
        setThumbNail(bundle.getString(THUMBNAIL));
        setDeviceType(bundle.getInt(DEVICETYPE, -0x1));
        setAlbum(bundle.getString(ALBUM));
        setArtist(bundle.getString(ARTIST));
        setTitle(bundle.getString(TITLE));
        setPhysicId(bundle.getString(PHYSIC_ID));
        setMimeType(bundle.getString(MIMETYPE));
        setResUri(bundle.getString(RES_URI));
        setObjectId(bundle.getString(OBJECT_ID));
        setResoulution(bundle.getString(RESOULUTION));
        setDuration(bundle.getString(DURATION));
        setFileAllName(bundle.getString(FILE_ALL_NAME));
    }

    public String getFileName() {
        return mFileName;
    }

    public void setFileName(String mFileName) {
        this.mFileName = mFileName;
    }

    public String getParentPath() {
        return mParentPath;
    }

    public void setParentPath(String mParentPath) {
        this.mParentPath = mParentPath;
    }

    public int getFolders() {
        return mFolders;
    }

    public void setFolders(int mFolders) {
        this.mFolders = mFolders;
    }

    public int getFiles() {
        return mFiles;
    }

    public void setFiles(int mFiles) {
        this.mFiles = mFiles;
    }

    public int getFileType() {
        return mFileType;
    }

    public void setFileType(int mFileType) {
        this.mFileType = mFileType;
    }

    public long getFileSize() {
        return mFileSize;
    }

    public void setFileSize(long mFileSize) {
        this.mFileSize = mFileSize;
    }

    public int getOrderField() {
        return mOrderField;
    }

    public void setOrderField(int mOrderField) {
        this.mOrderField = mOrderField;
    }

    public int getModifyDate() {
        return mModifyDate;
    }

    public void setModifyDate(int mModifyDate) {
        this.mModifyDate = mModifyDate;
    }

    public String getModifyDateStr() {
        return mModifyDateStr;
    }

    public void setModifyDateStr(String mModifyDateStr) {
        this.mModifyDateStr = mModifyDateStr;
    }

    public String getPinyin() {
        return mPinyin;
    }

    public void setPinyin(String mPinyin) {
        this.mPinyin = mPinyin;
    }

    public String getData() {
        if ((mParentPath != null) && (mFileName != null)) {
            return getParentPath() + File.separator + getFileName();
        }
        return mData;
    }

    public void setData(String mData) {
        this.mData = mData;
    }

    public int getDeleteModeState() {
        return mDeleteModeState;
    }

    public void setDeleteModeState(int state) {
        this.mDeleteModeState = state;
    }

    public String getThumbNail() {
        return mThumbNail;
    }

    public void setThumbNail(String thumbNail) {
        this.mThumbNail = thumbNail;
    }

    public String getAlbum() {
        return mAlbum;
    }

    public void setAlbum(String album) {
        this.mAlbum = album;
    }

    public String getArtist() {
        return mArtist;
    }

    public void setArtist(String artist) {
        this.mArtist = artist;
    }

    public String getTitle() {
        return mTitle;
    }

    public void setTitle(String title) {
        this.mTitle = title;
    }

    public int getDeviceType() {
        return mDeviceType;
    }

    public void setDeviceType(int mDeviceType) {
        this.mDeviceType = mDeviceType;
    }

    public String getPhysicId() {
        return mPhysicId;
    }

    public void setPhysicId(String mPhysicId) {
        this.mPhysicId = mPhysicId;
    }

    public String getMimeType() {
        return mMimeType;
    }

    public void setMimeType(String mMimeType) {
        this.mMimeType = mMimeType;
    }

    public String getResUri() {
        return mResUri;
    }

    public void setResUri(String mResUri) {
        this.mResUri = mResUri;
    }

    public String getObjectId() {
        return mObjectId;
    }

    public void setObjectId(String mObjectId) {
        this.mObjectId = mObjectId;
    }

    public String getResoulution() {
        return mResoulution;
    }

    public void setResoulution(String sResoulution) {
        this.mResoulution = sResoulution;
    }

    public String getUrl() {
        switch (this.mDeviceType) {
            default:
                return getData();
            case 20:
        }
        return this.mResUri;
    }

    public String getDuration() {
        return mDuration;
    }

    public void setDuration(String mDuration) {
        this.mDuration = mDuration;
    }

    public String getFileAllName() {
        return mFileAllName;
    }
    public void setFileAllName(String mFileAllName) {
        this.mFileAllName = mFileAllName;
    }
    public String getFileSizeStr() {
        return mFileSizeStr;
    }

    public void setFileSizeStr(String mFileSizeStr) {
        this.mFileSizeStr = mFileSizeStr;
    }
}
